<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/10 0010
 * Time: 下午 11:24
 */

namespace App\Command;

use App\Command\Lib\Command;
use App\Common\Download;
use App\Model\UploadVedioAndCover;

include APP_PATH . 'phpQuery/phpQuery.php';

/**
 * Class Meinv
 * @package App\Command
 */
class Meinv implements Command
{
    public function run()
    {

        for ($i = 72; $i < 73; $i++) {

            $data = file_get_contents('http://www.mm8.in/?ye=' . $i);
            $path = VEDIO_PATH . 'meimv'.DS;
            if (!file_exists($path)) {
                mkdir($path, 0777, true);
            }
            \phpQuery::newDocument($data);
            $aList = pq('div[class="box"] > a[class="item"]');
            foreach ($aList as $key => $a) {
                $href = pq($a)->attr("href");
                $image = pq($a)->find("img")->eq(0)->attr("src");
                if ($image && $href) {
                    $image = "http://" . substr($image, 2);
                    usleep(500000);
                    $vedioHtml = file_get_contents("http://www.mm8.in/" . $href);
                    \phpQuery::newDocument($vedioHtml);
                    $vedioLink = pq('video > source')->attr('src');
                    $titile = pq('title')->eq(0)->text();
                    $titile = trim(str_replace('#', '', $titile));
                    if ($vedioLink) {
                        if (!file_exists($path . "$titile.mp4")) {
                            Download::testDowlowd($vedioLink, $path . "$titile.mp4");
                            Download::getFile($image, $path, "$titile.jpg", 0);
                            if (file_exists($path . "$titile.mp4")) {
                                UploadVedioAndCover::upload($path . "$titile.mp4", $path . "$titile.jpg");
                            }
                        }
                    }
                    die();
                }
                die();

            }
        }

    }

    public static function desc()
    {
        return "抓取美女视频";
    }
}